<template>
	<view class="content">
		<view class="items" v-if="hasRequest" >
			<view v-for="(item,index) in list" :key="index">
				<view class="item" @click="gotoDetail(item)" @tap="gotoDetail(item)">
					<image :src="item.icon" mode="aspectFit"></image>
					<view :class="item.id">
						{{item.type}}
					</view>
				</view>
			</view>
		</view>
		<view v-else-if="!hasRequest" class="empty">
			<!-- 空白页 -->
			<image src="/static/emptyCart.jpg" mode="aspectFit"></image>
			<view class="empty-tips">
				未连接网络
				<view class="navigator">加载不出来~</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {},
				hasRequest: true,
			}
		},
		onLoad() {
			this.loadData();
		},
		methods: {
			async loadData() {
				const ip = await this.$api.json('ip');
				uni.request({
					url: ip + 'type/queryAll',
					success: (res) => {
						this.list = res.data
						this.hasRequest = true
					},
					fail: (res) => {
						this.hasRequest = false
					}
				});
			},
			navToList(sid, tid) {
				uni.navigateTo({
					url: `/pages/product/list?fid=${this.currentId}&sid=${sid}&tid=${tid}`
				})
			},
			gotoDetail(item) {
				// console.log(item)
				uni.navigateTo({
					url: `/pages/detail/detail?id=${item.id}&type=${item.type}`
				})
			}

		}
	}
</script>

<style lang='scss'>
	page,
	.content {
		height: 100%;
		width: 100%;
		background-color: #f8f8f8;
		display: flex;
	}


	/* 空白页 */
	.empty {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100vh;
		padding-bottom: 100upx;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
		background: #fff;

		image {
			width: 240upx;
			height: 160upx;
			margin-bottom: 30upx;
		}

		.empty-tips {
			display: flex;
			font-size: $font-sm+2upx;
			color: $font-color-disabled;

			.navigator {
				color: $uni-color-primary;
				margin-left: 16upx;
			}
		}
	}

	/* 容器样式 */
	.items {
		width: 100%;
		height: auto;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-between;
		margin: 60rpx;
		box-sizing: border-box;

		.item {
			padding-top: 40rpx;
			font-size: 30rpx;

			image {
				height: 100rpx;
				width: 100rpx;
			}

			text-align: center;
			width: 250rpx;
			height: 250rpx;
			border-bottom: 1rpx solid #D6D6D6;
			margin-top: 10rpx;
			margin-bottom: 110rpx;
		}
	}
</style>
